package minisoft.application.loterryservice;


import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


public class SearchAdapter extends BaseAdapter {

	private Context mContext;
	private Prize aItem;
	private List<Prize> mItems;
	private String[] prize_name;
	
	public SearchAdapter(Context c, Prize item) {
		mContext = c;
		aItem = item;
		prize_name = c.getResources().getStringArray(R.array.prize_name);
	}
	
	public SearchAdapter(Context c, List<Prize> items) {
		mContext = c;
		mItems = items;
		prize_name = c.getResources().getStringArray(R.array.prize_name);
	}
	
	@Override
	public int getCount() {
		return aItem.getPrizeArray().length;
	}

	@Override
	public String getItem(int position) {
		return aItem.getPrizeArray()[position];
	}
	
	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
		//Need to dynamic here
		//define region
		View aView = inflater.inflate( R.layout.prize_province_one_row, null );		
		
		//define number of column
		TextView name = (TextView)aView.findViewById(R.id.prize_name1);
		TextView value = (TextView)aView.findViewById(R.id.prize_value1);
		
		name.setText(prize_name[position]);
		value.setText(String.valueOf(aItem.getPrizeArray()[position]));		
		
		return aView;
	}
	
	public void setPrizeArray(String[] prize_name)
	{
		this.aItem.setPrizeArray(prize_name);
	}
	
	public void add(Prize aPrize)
	{
		mItems.add(aPrize);
	}
	public void update(Prize aPrize, int pos)
	{
		mItems.set(pos, aPrize);
	}	
	
	public void clear()
	{
		mItems.clear();
	}
}
